<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ include file="../include.jsp"%>
<style>
.site-block {
	padding: 20px;
	border: 1px solid #eee;
}

.site-text {
	position: relative;
}
</style>
<div class="site-block site-text">
	<form class="layui-form" action="">
		<div class="layui-form-item">
			<label class="layui-form-label">课程名称</label>
			<div class="layui-input-block">
				<input type="text" name="name" lay-verify="required" value="${row.name }" placeholder="请输入课程名称" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">课程日期</label>
			<div class="layui-input-block">
				<input type="text" name="beginTime" value="${row.beginTime }" lay-verify="required" placeholder="请选择课程时间" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">课程说明</label>
			<div class="layui-input-block">
				<textarea name="description" lay-verify="required" placeholder="请输入课程说明" class="layui-textarea">${row.description }</textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="hidden" name="id" value="${row.id }">
				<button class="layui-btn" lay-submit lay-filter="${moduleName }-${moduleAction }">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary" id="${moduleName }-${moduleAction }-reset">重置</button>
			</div>
		</div>
	</form>
</div>

<script>
layui.use(['form','laydate'], function() {
	var form = layui.form(),
	$ = layui.jquery;
	form.render();
	
	//自定义验证规则
	  form.verify({
		  name: function(value){
		      if(value.length < 4){
		        return '课程名称至少得4个字符啊';
		      }
		  }
	    
	  });
	//监听提交
	form.on('submit(${moduleName }-${moduleAction })', function(data) {
	//	layer.msg(JSON.stringify(data.field));
		var tmpIndex = layer.load({shade: [0.8, '#393D49']});
	    $.post('${ctx}/teacher/${moduleName }/${moduleAction}',data.field,function(rst){
	    	console.debug(rst);
	    	layer.close(tmpIndex);
	    	if(!rst){
	    		layer.msg('网络连接错误，请稍后再试。。。', {
	    			icon: 2,
	    			shade: [0.8, '#393D49'],
    			  	anim: 6
    			});
	    		return ;
	    	}
	    	
	    	if('error' == rst.code){
	    		layer.msg(rst.message, {
	    			time:2000,
	    			icon: 2,
	    			shade: [0.8, '#393D49'],
    			  	anim: 6
    			});
	    		return ;
	    	}
	    	layer.confirm('修改成功,留在本页继续添加?',{icon: 3, title:'提示'}
	    	, function(index){
	    		layer.close(index);
	    		$('#${moduleName }-${moduleAction }-reset').trigger('click') ;
	    	}
	    	, function(index){
	    		layer.closeAll();
	    		$('#${moduleName }SearchBtn').trigger('click') ;
	    	});       
	    	
	    },'json');
	
		return false;
	});
});
</script>